#!/bin/bash

ROOT=$(cd $(dirname $0)/../../; pwd)

set -o errexit
set -o nounset
#set -o pipefail


export CA_BUNDLE=$(kubectl config view --raw --flatten -o json | jq -r '.clusters[] | select(.name == "'$(kubectl config current-context | awk -F'@' '{print $NF}')'") | .cluster."certificate-authority-data"')

#if command -v envsubst >/dev/null 2>&1; then
#    envsubst -v ${CA_BUNDLE}
#else
    sed -i "s|\${CA_BUNDLE}|${CA_BUNDLE}|g" 5-mutatingwebhook.yaml
#fi
